Skip to content

Speed up loading file statuses in Git commit dialog by batching events and skipping events for up-to-date files#9324

Open
OndroMih wants to merge 1 commit intoapache:masterfrom
OndroMih:ondromih-git-commit-dlg-optimization-skip-no-update
Open

Speed up loading file statuses in Git commit dialog by batching events and skipping events for up-to-date files#9324
OndroMih wants to merge 1 commit intoapache:masterfrom
OndroMih:ondromih-git-commit-dlg-optimization-skip-no-update

Conversation

@OndroMih
Copy link
Copy Markdown
Contributor

@OndroMih OndroMih commented Apr 4, 2026

Skip firing events for up-to-date

Skip firing events for up-to-date files that are not
yet in the cache, since UPTODATE is the default for managed files.
This drastically reduces the time spent in the refreshStatusesBatch method on big repositories executed when Commit dialog opens. For example, on the Netbeans repository, from around 8 seconds to 20ms.

Batch status change notifications

Batch status change notifications to avoid per-file event overhead.

Replace per-file PROP_FILE_STATUS_CHANGED firing in refreshStatusesBatch
with a single PROP_FILES_STATUS_CHANGED batch event, eliminating 100k
redundant propertyChange/schedule/SwingUtilities.invokeLater calls on
first load. This improves performance a bit because it eliminates many method calls.
However, in the end, the number of files changed is the same so the event handler
still needs to process all of them.

Move status updates to a background thread

File status update requires I/O operation to refresh files metadata from FS. This is very slow when many files need to be updated. Moving them to a background thread offloads this slow operation from the main thread.
Updates can run asynchrnously without blocking the main thread that fires the status events, they just update UI hints, they have no impact no behavior.
For the whole Netbeans repository, this shortens the time it takes to complete the firePropertyChange event from 6 seconds to 1 second.

Complements #9304, which speeds up the process even more, in a different area.


Click to collapse/expand PR instructions

PR approval and merge checklist:

  1. Was this PR correctly labeled, did the right tests run? When did they run?
  2. Is this PR squashed?
  3. Are author name / email address correct? Are co-authors correctly listed? Do the commit messages need updates?
  4. Does the PR title and description still fit after the Nth iteration? Is the description sufficient to appear in the release notes?

If this PR targets the delivery branch: don't merge. (full wiki article)

@mbien mbien added git [ci] enable versioning job ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Apr 4, 2026
@apache apache locked and limited conversation to collaborators Apr 4, 2026
@apache apache unlocked this conversation Apr 4, 2026
Copy link
Copy Markdown
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good to me. Thanks a lot for the improvements.

left some comments inline but its nothing important

Comment on lines -582 to +589
for (ChangedEvent event : events) {
fireFileStatusChanged(event);
if (!events.isEmpty()) {
listenerSupport.firePropertyChange(PROP_FILES_STATUS_CHANGED, null, events);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. aggregating events can certainly reduce overhead under load. Reminds me a little on #8955 where I saw 1.5mil event handler invocations when a large project group opened.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the overhead reduction is almost negligible. I was tempted to remove this but then I found out one more way to optimize this, by running the property change listeners asynchronously in background thread.

Each single file status update is an I/O operation and thus slow. Running the updates in background moves this off the main thread. Running everything in batch allows offloading everything to a single background thread instead of updating each file in separate thread, which might be slower because of synchronization between threads.

Therefore I kept the property change event for all of the files and changed the 2 listeners to run in background, updating all the files with a single background thread.

fireStatusChanged(changedEvent.getFile());
} else if (event.getPropertyName().equals(FileStatusCache.PROP_FILES_STATUS_CHANGED)) {
List<FileStatusCache.ChangedEvent> changedEvents = (List<FileStatusCache.ChangedEvent>) event.getNewValue();
Set<File> files = new HashSet<>(changedEvents.size());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is super nitpicky. but the constructor arg isn't for the element count, it is to size the internal table - which sometimes leads to initial sizes which are too small.

if you want you can bump the module to javac.release=21 (see project.properties) and then use the HashSet.newHashSet(numElements) factory which does some math before setting the size of the internal table.

feel free to update the commit and force push in place.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated as suggested

Comment on lines +1138 to +1140
for (FileStatusCache.ChangedEvent changedEvent : changedEvents) {
if (revisionLeft == Revision.HEAD // remove when we're able to refresh single file changes for Local vs. any revision
&& revisionRight == Revision.LOCAL && affectsView(changedEvent)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could the revisionLeft/Right check be moved before the loop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated as suggested

@OndroMih OndroMih force-pushed the ondromih-git-commit-dlg-optimization-skip-no-update branch from 94bdb4a to e48d9d6 Compare April 7, 2026 11:24
@mbien
Copy link
Copy Markdown
Member

mbien commented Apr 7, 2026

@OndroMih for some reason I see an extra commit in this PR branch.

git pull --rebase --autostash git@github.com:apache/netbeans master
should hopefully resolve it.

@OndroMih
Copy link
Copy Markdown
Contributor Author

OndroMih commented Apr 7, 2026

@mbien , I implemented the changes you requested, please review again.

I added one more optimization - property change listeners run asynchronously - they both do a slow I/O operation for each file and running them asynchronously unblocks the main thread. This doesn't have impact on functionality because the final stage of updating the statuses was already asynchronous and it only updates the icons of files to reflect they status.

Here's a sceenshot from profile before the change - the firePropertyChange event took 6 seconds:
image

After these changes, when I forced update also on noupdate files, this decreased to 1 second:
image

When I put back skipping update on noupdate files, the firePropertyChange method is rarely called at all. And if it is, then only with a few files that are not marked with noupdate.

@OndroMih OndroMih force-pushed the ondromih-git-commit-dlg-optimization-skip-no-update branch from e48d9d6 to 2f76482 Compare April 7, 2026 12:17
@OndroMih
Copy link
Copy Markdown
Contributor Author

OndroMih commented Apr 7, 2026

@mbien

@OndroMih for some reason I see an extra commit in this PR branch.

Thanks, I did it and it seems it helped.

Comment on lines 299 to 305
final RequestProcessor.Task refreshAnnotationsTask = rp.create(() -> {

if (files == null) {
LOG.log(Level.FINE, "refreshing all annotations"); //NOI18N
refreshAllAnnotationsTask.schedule(2000);
return;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first if check could be before the task in the refreshAnnotations() method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed. Thanks.

@mbien mbien self-requested a review April 7, 2026 12:46
## Skip firing events for up-to-date 

Skip firing events for up-to-date files that are not
yet in the cache, since UPTODATE is the default for managed files. 
This drastically reduces the time spent in the refreshStatusesBatch method on big repositories executed when Commit dialog opens. For example, on the Netbeans repository, from around 8 seconds to 20ms.

## Batch status change notifications

Batch status change notifications to avoid per-file event overhead.

Replace per-file PROP_FILE_STATUS_CHANGED firing in refreshStatusesBatch
with a single PROP_FILES_STATUS_CHANGED batch event, eliminating 100k
redundant propertyChange/schedule/SwingUtilities.invokeLater calls on
first load. This improves performance a bit because it eliminates many method calls. 
However, in the end, the number of files changed is the same so the event handler 
still needs to process all of them.

## Move status updates to a background thread

File status update requires I/O operation to refresh files metadata from FS. This is very slow when many files need to be updated. Moving them to a background thread offloads this slow operation from the main thread.
Updates can run asynchronously without blocking the main thread that fires the status events, they just update UI hints, they have no impact no behavior.
For the whole Netbeans repository, this shortens the time it takes to complete the firePropertyChange event from 6 seconds to 1 second.
@OndroMih OndroMih force-pushed the ondromih-git-commit-dlg-optimization-skip-no-update branch from 2f76482 to 642c71b Compare April 7, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) git [ci] enable versioning job performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants